# Set ability to capture on start and restore on exit window data when running an application
#setw -g alternate-screen on

# use UTF8
set -g utf8
set-window-option -g utf8 on

set -g history-limit 10000

# set window and pane index to 1 (0 by default)
set-option -g base-index 1
setw -g pane-base-index 1

# Renumber windows
set-option -g renumber-windows on

### Keys settings

# For vim compatibility
set -g default-terminal "screen-256color"
set-window-option -g xterm-keys on
set -sg escape-time 0

# Change prefix to C-a
unbind C-b
set -g prefix C-a
# use send-prefix to pass C-a through to application
bind-key C-a send-prefix

# reload ~/.tmux.conf using PREFIX r
bind-key r source-file ~/.tmux.conf \; display "Reloaded!"

# disable pane switching after first keystroke
set-option -g repeat-time 200

# Splitting windows into panes with h and v
bind-key | split-window -h -c '#{pane_current_path}'
bind-key - split-window -v -c '#{pane_current_path}'

#new pane start in the current directory - update needed by tmux 1.9
bind-key c new-window -c '#{pane_current_path}'

# Alt arrow to switch windows
bind-key -n M-Left  previous-window
bind-key -n M-Right next-window

# Press C-l C-k to completely wipe terminal history and tmux history
bind-key -n C-k clear-history

# Set up resize-pane keys
unbind-key C-up
unbind-key C-down
unbind-key C-left
unbind-key C-right
bind-key -r j resize-pane -D 3
bind-key -r h resize-pane -L 3
bind-key -r k resize-pane -U 3
bind-key -r l resize-pane -R 3

bind-key P command-prompt -p 'save history to filename:' -I '~/tmux-history.txt' 'capture-pane -S - ; save-buffer %1 ; delete-buffer'

bind-key -n C-S-Left swap-window -t -1
bind-key -n C-S-Right swap-window -t +1

### Mouse settings

# Sane scrolling
set -ga terminal-overrides ',xterm*:smcup@:rmcup@'
# Make mouse useful in copy mode
set -g mouse on
bind -T root WheelUpPane   if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M"
bind -T root WheelDownPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; send-keys -M"
set -g mouse-utf8 off
# ----------------------
# set some pretty colors
# ----------------------
# set pane colors - highlight the active pane
set-option -g pane-border-fg colour235 #base02
set-option -g pane-active-border-fg colour240 #base01

# colorize messages in the command line
set-option -g message-bg black #base02
set-option -g message-fg brightred #orange

# ----------------------
# Status Bar
# -----------------------
set-option -g status on                # turn the status bar on
set -g status-utf8 on                  # set utf-8 for the status bar
set -g status-interval 5               # set update frequencey (default 15 seconds)
set -g status-justify centre           # center window list for clarity
# set-option -g status-position top    # position the status bar at top of screen

# visual notification of activity in other windows
setw -g monitor-activity on
set -g visual-activity on

# set color for status bar
set-option -g status-bg colour235 #base02
set-option -g status-fg yellow #yellow
set-option -g status-attr dim

# set window list colors - red for active and cyan for inactive
set-window-option -g window-status-fg brightblue #base0
set-window-option -g window-status-bg colour236
set-window-option -g window-status-attr dim

set-window-option -g window-status-current-fg brightred #orange
set-window-option -g window-status-current-bg colour236
set-window-option -g window-status-current-attr bright

# show host name and IP address on left side of status bar
set -g status-left-length 70
set -g status-left "#[fg=green]: #h : #[fg=brightblue]#(ip addr show dev eth0 | grep 'inet ' | awk '{print \"eth0 \" $2}') #(ip addr show dev eth1 | grep 'inet ' | awk '{print \"eth1 \" $2}') #(ip addr show dev eth2 | grep 'inet ' | awk '{print \"eth2 \" $2}')"

# show session name, window & pane number, date and time on right side of
# status bar
set -g status-right-length 60
set -g status-right "#[fg=blue]#S #I:#P #[fg=yellow]:: %d %b %Y #[fg=green]:: %l:%M %p :: #(date -u | awk '{print $4}')::"

